package com.github.aloxc.plugin.restplus.entity;

import com.github.aloxc.plugin.DonotGuard;
import com.intellij.ide.util.PropertiesComponent;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 请求结果显示方式
 * @author leero
 */
@DonotGuard
public enum Show{
    /**
     * 代码
     */
    @DonotGuard
    CODE("code"),
    /**
     * 树
     */
    @DonotGuard
    TREE("tree");
    private Show(String type) {
        this.type = type;
    }

    public String getType() {
        return type;
    }

    private String type;

    private static Map<String,Show> MAP = Arrays.stream(Show.values()).collect(Collectors.toMap(k->k.getType().trim(), v->v));
    public static Show getByType(String type){
        if(type == null){
            return CODE;
        }
        return MAP.get(type.toLowerCase());
    }

    public static Show get(){
        PropertiesComponent instance = PropertiesComponent.getInstance();
        String show = instance.getValue(Show.class.getName());
        return getByType(show);
    }

    public static void set(Show show){
        PropertiesComponent instance = PropertiesComponent.getInstance();
        instance.setValue(Show.class.getName(),show.getType());
    }
}